// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-6

#ifndef __NET_OVERLAPPED_H_COMMON_SERVLIB__
#define __NET_OVERLAPPED_H_COMMON_SERVLIB__

#pragma once

#include "net_config.h"
#include <common/base/mempool.h>

namespace JoyServer
{

class CJoySockData;

// base class of asynchronous operations.
// we post the CJoyOverlapped structures to the completion port.
// the derived class should override OnComletion method.
// this class inherits from CJoyPoolObject for fast memory allocation.
class CJoyOverlapped : public CJoyPoolObject
{
protected:

    WSAOVERLAPPED   m_overlapped;
    CJoySockData*   m_sockData;

public:
    CJoyOverlapped(CJoySockData* sockData);
    virtual ~CJoyOverlapped();

    virtual void OnComletion(DWORD dwTransferred, DWORD err);

    WSAOVERLAPPED* ToOsOverlapped()
    {
        return &m_overlapped;
    }

    static CJoyOverlapped* FromOsOverlapped(WSAOVERLAPPED* pOverlapped)
    {
        return (CJoyOverlapped*)((char*)pOverlapped - offsetof(CJoyOverlapped, m_overlapped));
    }
};

} // namespace JoyServer

#endif  // __NET_OVERLAPPED_H_COMMON_SERVLIB__